﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Medical.Business;

/// <summary>
/// 答疑列表
/// </summary>
public partial class webadmin_FeedBackList : AdminPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            InitSort();
            InitData();
        }
    }

    /// <summary>
    /// 权限控制
    /// </summary>
    /// <returns></returns>
    public override long GetNeededFeatures()
    {
        return AdminFEATURE.FeedBack;
    }

    /// <summary>
    /// 页面数据初始化
    /// </summary>
    protected void InitData()
    {
        int nSortID = Convert.ToInt32(ddlSort.SelectedValue);
        string strName = txtName.Text.Trim();
        int nRecordCount = 0;
        int nPageCount = 0;
        //列表绑定
        DataTable dt = new BisFeedBack().GetFeedBackList(nSortID, nAdminFeatures == 1 ? Convert.ToInt32(ddlAdmin.SelectedValue) : nAdminUserID, null, strName, 0, txtBeginTime.Text.Trim(), txtEndTime.Text.Trim(), anpPage.CurrentPageIndex, anpPage.PageSize, ref nPageCount, ref nRecordCount);
        anpPage.RecordCount = nRecordCount;
        if (nRecordCount == 0)
        {
            noData.Style["display"] = "block";
        }
        else
        {
            noData.Style["display"] = "none";
        }
        rptFeedBack.DataSource = dt;
        rptFeedBack.DataBind();
        dt.Dispose();
    }

    /// <summary>
    /// 初始化分类下拉框
    /// </summary>
    protected void InitSort()
    {
        BisSortInfo bisSort = new BisSortInfo();
        ddlSort.Items.Add(new ListItem("所有分类", "0"));
        //绑定分类下拉框
        DataTable dtSortList = bisSort.GetAllSortList(ArticelTypeEnum.FeedBack);
        if (dtSortList != null && dtSortList.Rows.Count > 0)
        {
            int nSortIndex = 0;
            foreach (DataRow dr in dtSortList.Rows)
            {
                nSortIndex = Convert.ToInt32(dr["SortIndex"]);
                ddlSort.Items.Add(new ListItem(Common.GetSortIcon(nSortIndex) + dr["Name"].ToString(), dr["ID"].ToString()));
            }
            dtSortList.Dispose();
        }
        BisAdminInfo bisAdminInfo = new BisAdminInfo();
        ddlAdmin.Items.Add(new ListItem("全部", "0"));
        DataTable dtAdmin = bisAdminInfo.GetAdminList();
        foreach (DataRow drAdmin in dtAdmin.Rows)
        {
            ddlAdmin.Items.Add(new ListItem(drAdmin["UserName"].ToString(), drAdmin["ID"].ToString()));
        }
        if (!SupportFeatures(1))
        {
            ltlMan.Visible = false;
            ddlAdmin.Visible = false;
        }
    }

    /// <summary>
    /// 列表事件
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    protected void rptFeedBack_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {

            //删除信息
            bool result = new BisFeedBack().Delete(Convert.ToInt32(e.CommandArgument.ToString()));
            Until.Alert(result ? "删除成功！" : "删除失败！");
            InitData();
        }
    }
    /// <summary>
    /// 分页事件
    /// </summary>
    /// <param name="src"></param>
    /// <param name="e"></param>
    protected void anpPage_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        anpPage.CurrentPageIndex = e.NewPageIndex;
        InitData();
    }

    /// <summary>
    /// 查询
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        anpPage.CurrentPageIndex = 1;
        InitData();
    }

    /// <summary>
    /// 重置
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnReset_Click(object sender, EventArgs e)
    {
        anpPage.CurrentPageIndex = 1;
        txtName.Text = "";
        ddlSort.SelectedValue = "0";
        InitData();
    }

}